/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.science_meeting.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.science_meeting.entity.TbScienceMeeting;
import com.thinkgem.jeesite.modules.science_meeting.service.TbScienceMeetingService;

/**
 * 举办学术会议Controller
 * @author hang
 * @version 2017-01-14
 */
@Controller
@RequestMapping(value = "${adminPath}/science_meeting/tbScienceMeeting")
public class TbScienceMeetingController extends BaseController {

	@Autowired
	private TbScienceMeetingService tbScienceMeetingService;
	
	@ModelAttribute
	public TbScienceMeeting get(@RequestParam(required=false) String id) {
		TbScienceMeeting entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = tbScienceMeetingService.get(id);
		}
		if (entity == null){
			entity = new TbScienceMeeting();
		}
		return entity;
	}
	
	@RequiresPermissions("science_meeting:tbScienceMeeting:view")
	@RequestMapping(value = {"list", ""})
	public String list(TbScienceMeeting tbScienceMeeting, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TbScienceMeeting> page = tbScienceMeetingService.findPage(new Page<TbScienceMeeting>(request, response), tbScienceMeeting); 
		model.addAttribute("page", page);
		return "modules/science_meeting/tbScienceMeetingList";
	}

	@RequiresPermissions("science_meeting:tbScienceMeeting:view")
	@RequestMapping(value = "form")
	public String form(TbScienceMeeting tbScienceMeeting, Model model) {
		model.addAttribute("tbScienceMeeting", tbScienceMeeting);
		return "modules/science_meeting/tbScienceMeetingForm";
	}

	@RequiresPermissions("science_meeting:tbScienceMeeting:edit")
	@RequestMapping(value = "save")
	public String save(TbScienceMeeting tbScienceMeeting, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, tbScienceMeeting)){
			return form(tbScienceMeeting, model);
		}
		tbScienceMeetingService.save(tbScienceMeeting);
		addMessage(redirectAttributes, "保存举办学术会议成功");
		return "redirect:"+Global.getAdminPath()+"/science_meeting/tbScienceMeeting/?repage";
	}
	
	@RequiresPermissions("science_meeting:tbScienceMeeting:edit")
	@RequestMapping(value = "delete")
	public String delete(TbScienceMeeting tbScienceMeeting, RedirectAttributes redirectAttributes) {
		tbScienceMeetingService.delete(tbScienceMeeting);
		addMessage(redirectAttributes, "删除举办学术会议成功");
		return "redirect:"+Global.getAdminPath()+"/science_meeting/tbScienceMeeting/?repage";
	}

}